// @algorithm @lc id=100282 lang=cpp
// @title cong-wei-dao-tou-da-yin-lian-biao-lcof

#include "algm/algm.h"
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    vector<int> reversePrint(ListNode *head) {
        stack<int> s;
        vector<int> ans;
        if (!head) {
            return {};
        }
        while (head) {
            s.push(head->val);
            head = head->next;
        }
        while (!s.empty()) {
            ans.push_back(s.top());
            s.pop();
        }
        return ans;
    }
};